//
//  MainViewController.m
//  Camera
//
//  Created by aaaaaa on 16/8/10.
//  Copyright © 2016年 葛海一. All rights reserved.
//

#import "MainViewController.h"
#import "MainGuideCollectionViewCell.h"
#import "GHYCameraViewController.h"
#import "RQMCommunityViewController.h"

#import "LAB_PhotoAlbumViewController.h"


@interface MainViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>


@property (nonatomic, retain) NSArray *titleArray;
@property (nonatomic, retain) NSArray *imageNameArray;
@property (nonatomic, retain) UIImageView *imageView;
@property (nonatomic, retain) BaseCollectionView *collectionView;

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    [self config];
    UIImage *image = [UIImage imageNamed:@"7e6c1a0b394e0ce1b02a13ece50ddaa3"];
    UIImageView *view = [[UIImageView alloc]initWithImage:image];
    view.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:view];
    
    self.titleArray = @[@"特效相机", @"美化图片", @"社区"];
    self.imageNameArray = @[@"icon_camera", @"icon_editor", @"icon_component_list"];
    
    [self createImageView];
    [self createCollectionView];
    
    

    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self config];
}


- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;
//    self.isHiddenStatus = NO;
//    [self prefersStatusBarHidden];
}






- (void)config{
     self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.hidden = YES;
//    self.isHiddenStatus = YES;
//    [self prefersStatusBarHidden];
}






// 背景图片
- (void)createImageView{
    
    self.imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    //    self.imageView.image
    [self.view addSubview:_imageView];
    
}

- (void)createCollectionView{
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.minimumLineSpacing = 0;
    flowLayout.itemSize = CGSizeMake(WIDTH, HEIGHT * 0.09);
    
    self.collectionView = [[BaseCollectionView alloc] initWithFrame:CGRectMake(0, HEIGHT * 0.73, WIDTH, HEIGHT * 0.27) collectionViewLayout:flowLayout];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.backgroundColor= [UIColor clearColor];
    [self.collectionView registerClass:[MainGuideCollectionViewCell class] forCellWithReuseIdentifier:@"mainGuideCell"];
    
    [self.view addSubview:_collectionView];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.titleArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    MainGuideCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"mainGuideCell" forIndexPath:indexPath];
    
    cell.imageName = self.imageNameArray[indexPath.row];
    cell.titleStr = self.titleArray[indexPath.row];
    
    
    return cell;
    
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
        {
            GHYCameraViewController *cameraVc = [[GHYCameraViewController alloc] init];
            [self.navigationController pushViewController:cameraVc animated:YES];
        }
            break;
        case 1:
        {
            LAB_PhotoAlbumViewController *photoAlbumVc = [[LAB_PhotoAlbumViewController alloc] init];
            [self.navigationController pushViewController:photoAlbumVc animated:YES];

                   }
            break;
        case 2:
        {
            RQMCommunityViewController *community = [[RQMCommunityViewController alloc] init];
            [self.navigationController pushViewController:community animated:YES];

                    }
            break;
            
        default:
            break;
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
